const router = require('express').Router();
const fs = require('fs');
const {fileUploadPath} = require('../config/setting')

router.post('/', async (req, res) => {
    const files = req.files

    if (!fs.existsSync(fileUploadPath)){
        fs.mkdirSync(fileUploadPath);
    }

    files.forEach(fileOps => {
        const name = fileUploadPath + fileOps.originalname;
        const ws = fs.createWriteStream(name);
        ws.write(fileOps.buffer);
        ws.close();
    })

    res.send('ok')
})

module.exports = router